﻿using System;
using System.ComponentModel;
using System.Web.UI;
using HeroldIT.Dnn.JQuery.UI;

namespace HeroldIT.Dnn.JQuery.Extras
{
    /// <summary>
    /// Creates a <see cref="WindowedDialogChild"/> control.
    /// </summary>
    public class WindowedDialogChild : Control
    {
        #region properties

        /// <summary>
        /// Gets or sets whether to automatically register jQuery UI on the page.
        /// </summary>
        [Browsable(true)]
        [Localizable(false)]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Category("Behavior")]
        [DefaultValue(false)]
        public bool AutoRegister { get; set; }

        #endregion

        #region page lifecycle

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data. </param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (null != this.Page && this.Visible)
            {
                if (this.AutoRegister)
                {
                    this.Page.RegisterJQueryUI();
                }
                this.Page.ClientScript.RegisterClientScriptInclude(typeof(WindowedDialogChild), "WindowedDialogChild", this.ResolveUrl("~/DesktopModules/HeroldIT.JQuery.Extras/js/jquery-ui.windowedDialogChild.0.5.1.min.js"));
            }
        }

        /// <summary>
        /// Sends server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter"/> object, which writes the content to be rendered on the client.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> object that receives the server control content. </param>
        protected override void Render(HtmlTextWriter writer)
        {
        }

        #endregion
    }
}
